#from django.db import models
from google.appengine.ext import db

class Favicon(db.Model):
  mimetype = db.StringProperty(required=True)
  favicon_bytes = db.BlobProperty(required=True)
  active = db.BooleanProperty(default=True)
  accesses = db.IntegerProperty(default=0)
  created_at = db.DateTimeProperty(auto_now_add=True)
  modified_at = db.DateTimeProperty(auto_now=True)

class FaviconColor(db.Model):
  favicon = db.ReferenceProperty(Favicon)
  r = db.IntegerProperty(default=0)
  g = db.IntegerProperty(default=0)
  b = db.IntegerProperty(default=0)

class FaviconURI(db.Model):
  uri = db.StringProperty(required=True)
  favicon = db.ReferenceProperty(Favicon)
  created_at = db.DateTimeProperty(auto_now_add=True)
  modified_at = db.DateTimeProperty(auto_now=True)

class Client(db.Model):
  client_id = db.StringProperty(required=True)
  created_at = db.DateTimeProperty(auto_now_add=True)
  modified_at = db.DateTimeProperty(auto_now=True)

class Access(db.Model):
  created_at = db.DateTimeProperty(auto_now_add=True)
  favicon = db.ReferenceProperty(Favicon)
  favicon_uri = db.ReferenceProperty(FaviconURI)
  client = db.ReferenceProperty(Client)

# stats objects
class CountStat(db.Expando):
  count = db.IntegerProperty(default=0)
  type = db.StringProperty()
  since = db.DateTimeProperty()

class DateCountStat(db.Expando):
  date = db.DateTimeProperty()
  type = db.StringProperty()
  count = db.IntegerProperty(default=0)
